<?php
class LWNTempMsg{	
	//引用微信类，调用发送方法发送文本信息
	
	protected $user;
	protected $touser;
	protected $content;
	protected $error;
	protected $template_id;
	protected $url;
	public function  __construct($touser,$content,$template_id,$url){
		$this->touser=$touser;
		$this->content=$content;
		$this->template_id=$template_id;
		$this->url=$url;
	}
	
	
	public function sendMsg(){
		
		
		
		Vendor('Weixin.Weixin');
		$d['token']=getSysVal('token');
		$d['appid']=getSysVal('appid');
		$d['appsecret']=getSysVal('appsecret');
		$weixin=new WeixinChat($d);
		$data=[
			'touser'=>$this->touser,
			"template_id"=>$this->template_id,
			"url"=>$this->url,
			"topcolor"=>"#FF0000"
		];
		$num=0;
		foreach($this->content as $k => $v){
		
		if($k==='first'){
		$data['data']['first']['value']=$v;
		$data['data']['first']['color']="#173177";	
		continue;
		}
		if($k==='remark'){
		$data['data']['remark']['value']=$v;
		$data['data']['remark']['color']="#173177";	
		continue;
		}
		$num++;
		$key='keyword'.($num);
		$data['data'][$key]['value']=$v;
		$data['data'][$key]['color']="#173177";
		}
	
		$ret = $weixin -> sendTemplateMessage($data);
		if($ret){
			return true;
		}else{
			$this->error=$weixin->getError();
			return $weixin->getError();	
		}
	}
}